package com.dog.framework.feign.config;

import com.dog.framework.feign.core.OpenFeignErrorDecoder;
import feign.Feign;
import feign.Logger;
import feign.Retryer;
import feign.codec.ErrorDecoder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;

@Slf4j
@Configuration
@ComponentScan
@ConditionalOnClass(Feign.class)
public class FeignAutoConfig {

    /**
     * 开启openFeign的日志增强，生产环境中关闭
     * @return
     */
    @Profile(value = {"dev","test"})
    @Bean
    public Logger.Level level(){
        return Logger.Level.FULL;
    }


    /**
     * 自定义异常解码器
     * @return OpenFeignErrorDecoder
     */
    @Bean
    public ErrorDecoder errorDecoder(){
        return new OpenFeignErrorDecoder();
    }

    /**
     * 不重试
     */
    @Bean
    Retryer retryer(){
        return Retryer.NEVER_RETRY;
    }


}
